package com.zeny.edu.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zeny.edu.common.ResponseResult;
import com.zeny.edu.eduservice.entity.EduCourse;
import com.zeny.edu.eduservice.entity.EduTeacher;
import com.zeny.edu.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName FrontEduTeacherController
 * @Description 前台controller
 * @Author zeny
 * @Date 2020/3/9 0009 18:28
 */
@RestController
@RequestMapping("/eduservice/front/teacher")
@CrossOrigin
public class FrontEduTeacherController {
    @Autowired
    private EduTeacherService eduTeacherService;

    /**
     * @Description 前台分页列表
     * @Date 2020/3/9 0009 18:40
     * @param page
     * @param limit 
     * @return com.zeny.edu.common.ResponseResult
     **/
    @GetMapping("/{page}/{limit}")
    public ResponseResult getFrontTeacherListPage(@PathVariable Long page, @PathVariable Long limit) {
        Page<EduTeacher> teacherPage = new Page<>(page, limit);
        Map<String, Object> map = eduTeacherService.getFrontTeacherList(teacherPage);
        return ResponseResult.ok().data(map);
    }

    /**
     * @Description 前台根据讲师ID查询讲师信息以及其主讲的课程
     * @Date 2020/3/9 0009 19:12
     * @param id
     * @return com.zeny.edu.common.ResponseResult
     **/
    @GetMapping("/{id}")
    public ResponseResult getTeacherInfoAndCourse(@PathVariable String id) {
        EduTeacher teacher = eduTeacherService.getById(id);
        List<EduCourse> courseList = eduTeacherService.getCourseOfTeacherByTeacherId(id);
        return ResponseResult.ok().data("teacher", teacher).data("courses", courseList);
    }
}
